#region License

/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#endregion License

#region Includes

using System.Collections.Generic;
using System.Linq;

#endregion

namespace WaveTech.GShield.Data
{
	public static class LpqDAO
	{
		public static string GetQuestionById(int? id)
		{
			var question = from q in Database.DC.LPQuestions
			               where q.Id == id
			               select q;

			return question.Single().Question;
		}

		public static int GetIdByQuestion(string question)
		{
			var id = from q in Database.DC.LPQuestions
			         where q.Question == question
			         select q;

			return id.Single().Id;
		}

		public static List<string> GetAllQuestions()
		{
			var questions = from q in Database.DC.LPQuestions
			                select q.Question;

			return questions.ToList();
		}
	}

	#region Old LpqDAO

	/*
  /// <summary>
  /// Lost Password Questions Data Access Objects
  /// </summary>
  public class LpqDAO
  {
    #region Get Questions
    /// <summary>
    /// Retrieves all the possible Lost Password Questions.
    /// </summary>
    /// <returns>Arraylist of Lost Password Question strings</returns>
    public ArrayList GetQuestions()
    {
      ArrayList l = new ArrayList();
      Database db;
      DbCommand dbCommand;

      db = DatabaseFactory.CreateDatabase();
			dbCommand = db.GetSqlStringCommand(@"SELECT [Question]
																						FROM dbo.LPQuestions");

      DataSet ds = db.ExecuteDataSet(dbCommand);

      foreach (DataRow r in ds.Tables[0].Rows)
      {
        l.Add(r[0]);
      }

      return l;
    }
    #endregion Get Questions

    #region Get Id By Question
    /// <summary>
    /// Queries the database and retrives an Id by a questions text.
    /// </summary>
    /// <param name="question">Question to retrieve the Id for.</param>
    /// <returns>Question's Id Number</returns>
    public int? GetIdByQuestion(string question)
    {
      if (question == null || question.Length <= 0)
        throw new ArgumentNullException("question");

      Database db;
      DbCommand dbCommand;

      db = DatabaseFactory.CreateDatabase();
			dbCommand = db.GetSqlStringCommand(@"SELECT Id
																						FROM LPQuestions
																						WHERE (Question = @Question)");

      db.AddInParameter(dbCommand, "@Question", DbType.String, question);

      object o = db.ExecuteScalar(dbCommand);

      if (o == null)
        return null;
      else
        return (int)o;
    }
    #endregion Get Id By Question

    #region Get Question By Id
    /// <summary>
    /// Queries the database and retrieves a question
    /// </summary>
    /// <param name="id">Id number of the Question to retrieve</param>
    /// <returns>Text of the Question</returns>
    public string GetQuestionById(int? id)
    {
      if (id == null)
        throw new ArgumentNullException("id");

      Database db = DatabaseFactory.CreateDatabase();
			DbCommand dbCommand = db.GetSqlStringCommand(@"SELECT Question
																											FROM LPQuestions
																											WHERE ([Id] = @Id)");

      db.AddInParameter(dbCommand, "@Id", DbType.String, id);

      object o = db.ExecuteScalar(dbCommand);

      if (o == null)
        return null;
      else
        return o.ToString();
    }
    #endregion Get Id By Question
  }
    */

	#endregion Old LpqDAO
}